//============================================================================
// Copyright (C) 2003-2013 Brett R. Jones 
// All Rights Reserved
//
// You may redistribute and/or modify for non commercial and commercial uses 
// provided this copyright notice remains in place and is not modified
//
// This code is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// brettjones1900@gmail.com
// http://www.p2panarchy.com
//============================================================================
#include "RcSysPktLib.h"

//=== constructor ===//
RcSysPktAnnList::RcSysPktAnnList()
{ 
	m_u16PktLen = EmptyLen(); 
	m_u16PktType = RC_SYS_PKT_TYPE_ANN_LIST; 
	m_u16Flags = 0;
	m_u16ListCnt = 0; 
	m_u16Reason = 0;
	m_u16Res1 = 0;
	m_u32Res2 = 0;
}
//=== methods ===//
int RcSysPktAnnList::EmptyLen( void )
{  
	return sizeof( RcSysPktAnnList ) - MAX_RC_SYS_PKT_ANN_LIST_LEN ; 
}

void RcSysPktAnnList::FinalizeLen( void )
{ 
	m_u16PktLen = ROUND_TO_16BYTE_BOUNDRY( m_u16PktLen ); 
}

RCODE RcSysPktAnnList::AddAnn( RcSysPktAnnBase * poPktAnn )
{
	if( sizeof( RcSysPktAnnBase ) * m_u16ListCnt > MAX_RC_SYS_PKT_ANN_LIST_LEN )
	{
		return -1;
	}
	int iOffs = m_u16PktLen - EmptyLen();
	memcpy( &m_au8List[ iOffs ], poPktAnn, sizeof( RcSysPktAnnBase ) );
	(( RcSysPktAnnBase *)&m_au8List[ iOffs ])->m_u16PktLen = sizeof( RcSysPktAnnBase );
	m_u16ListCnt++;
	m_u16PktLen += sizeof( RcSysPktAnnBase );
	return 0;
}
